﻿using XinLife.Application.Interface;
using XinLife.Common;
using XinLife.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using XinLife.Core.Model;
using XinLife.Core.Helper;
using XinLife.Common.Filters;

namespace XinLife.Controllers.Admin
{
    /// <summary>
    /// 系统配置
    /// </summary>
    public class SystemConfigController : BaseController
    {
        ISystemConfigService _systemConfigService;
        public SystemConfigController(ISystemConfigService systemConfigService)
        {
            _systemConfigService = systemConfigService;
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        [HttpGet]
        public async Task<object> GetSystemConfigPageList([FromQuery] Pagination pagination, [FromQuery] string queryJson = null)
        {
            return await _systemConfigService.GetSystemConfigPageList(pagination, queryJson);
        }
        /// <summary>
        /// 获取表单信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<AjaxResult> GetSystemConfigForm(string id)
        {
            return await _systemConfigService.GetSystemConfigForm(id);
        }
        /// <summary>
        /// 编辑
        /// </summary>-
        /// <returns></returns>
        [HttpPost]
        public async Task<AjaxResult> EditSystemConfig([FromForm] SystemConfig systemConfig)
        {
            return await _systemConfigService.EditSystemConfig(systemConfig);
        }
        /// <summary>
        /// 删除
        /// </summary>
        [HttpPost]
        public async Task<AjaxResult> DelSystemConfig([FromForm] string ids)
        {
            return await _systemConfigService.DelSystemConfig(ids);
        }

        /// <summary>
        /// 导出数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<FileContentResult> Export([FromQuery] string queryJson = null)
        {
            var dt = await _systemConfigService.GetTableToExecl(queryJson);
            var bytes = ExcelUtil.ExportExcel(dt);
            return File(bytes, "application/octet-stream","系统配置数据");
        }
    }
}
